package com.lxmes.sales.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.sales.domain.NcPurchaseFormalPlan;
import com.lxmes.sales.service.INcPurchaseFormalPlanService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 采购正式计划Controller
 *
 * @author lx
 * @date 2023-06-06
 */
@Api(tags = "采购正式计划")
@RestController
@RequestMapping("/sales/NcPurchaseFormalPlan")
public class NcPurchaseFormalPlanController extends BaseController
{
    @Autowired
    private INcPurchaseFormalPlanService ncPurchaseFormalPlanService;

    /**
     * 查询采购正式计划列表
     */
    @ApiOperation("查询采购正式计划列表")
    @PreAuthorize("@ss.hasPermi('sales:NcPurchaseFormalPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcPurchaseFormalPlan ncPurchaseFormalPlan)
    {
        startPage();
        List<NcPurchaseFormalPlan> list = ncPurchaseFormalPlanService.selectNcPurchaseFormalPlanList(ncPurchaseFormalPlan);
        return getDataTable(list);
    }
    /**
     * 查询采购正式计划列表
     */
    @ApiOperation("查询采购正式计划列表")
    @PreAuthorize("@ss.hasPermi('sales:NcPurchaseFormalPlan:list')")
    @GetMapping("/listSelect")
    public TableDataInfo listSelect(NcPurchaseFormalPlan ncPurchaseFormalPlan)
    {
        List<NcPurchaseFormalPlan> list = ncPurchaseFormalPlanService.selectNcPurchaseFormalPlanBySupplierCode(ncPurchaseFormalPlan);
        return getDataTable(list);
    }
    /**
     * 查询采购正式计划列表
     */
    @ApiOperation("查询采购正式计划列表")
    @PreAuthorize("@ss.hasPermi('sales:NcPurchaseFormalPlan:list')")
    @GetMapping("/getNcPurchaseFormalPlanByPlanNumber")
    public TableDataInfo getNcPurchaseFormalPlanByPlanNumber(NcPurchaseFormalPlan ncPurchaseFormalPlan)
    {
        List<NcPurchaseFormalPlan> list = ncPurchaseFormalPlanService.getNcPurchaseFormalPlanByPlanNumber(ncPurchaseFormalPlan);
        return getDataTable(list);
    }

    /**
     * 导出采购正式计划列表
     */
    @ApiOperation("导出采购正式计划列表")
    @PreAuthorize("@ss.hasPermi('sales:NcPurchaseFormalPlan:export')")
    @Log(title = "采购正式计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcPurchaseFormalPlan ncPurchaseFormalPlan)
    {
        List<NcPurchaseFormalPlan> list = ncPurchaseFormalPlanService.selectNcPurchaseFormalPlanList(ncPurchaseFormalPlan);
        ExcelUtil<NcPurchaseFormalPlan> util = new ExcelUtil<NcPurchaseFormalPlan>(NcPurchaseFormalPlan.class);
        util.exportExcel(response, list, "采购正式计划数据");
    }

    /**
     * 获取采购正式计划详细信息
     */
    @ApiOperation("获取采购正式计划详细信息")
    @PreAuthorize("@ss.hasPermi('sales:NcPurchaseFormalPlan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncPurchaseFormalPlanService.selectNcPurchaseFormalPlanById(id));
    }

    /**
     * 新增采购正式计划
     */
    @ApiOperation("新增采购正式计划")
    @PreAuthorize("@ss.hasPermi('sales:NcPurchaseFormalPlan:add')")
    @Log(title = "采购正式计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcPurchaseFormalPlan ncPurchaseFormalPlan)
    {
        return toAjax(ncPurchaseFormalPlanService.insertNcPurchaseFormalPlan(ncPurchaseFormalPlan));
    }

    /**
     * 修改采购正式计划
     */
    @ApiOperation("修改采购正式计划")
    @PreAuthorize("@ss.hasPermi('sales:NcPurchaseFormalPlan:edit')")
    @Log(title = "采购正式计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcPurchaseFormalPlan ncPurchaseFormalPlan)
    {
        return toAjax(ncPurchaseFormalPlanService.updateNcPurchaseFormalPlan(ncPurchaseFormalPlan));
    }

    /**
     * 删除采购正式计划
     */
    @ApiOperation("删除采购正式计划")
    @PreAuthorize("@ss.hasPermi('sales:NcPurchaseFormalPlan:remove')")
    @Log(title = "采购正式计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncPurchaseFormalPlanService.deleteNcPurchaseFormalPlanByIds(ids));
    }
    /**
     * 导入采购正式计划
     */
    @Log(title = "采购正式计划", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcPurchaseFormalPlan> util = new ExcelUtil<>(NcPurchaseFormalPlan.class);
        List<NcPurchaseFormalPlan> ncPurchaseFormalPlanList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncPurchaseFormalPlanService.imporIteminfo(ncPurchaseFormalPlanList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<NcPurchaseFormalPlan> util = new ExcelUtil<>(NcPurchaseFormalPlan.class);
        util.importTemplateExcel(response,"采购正式计划");
    }
}
